package com.example.stlink.utils.activityUtil;

import android.os.Handler;
import android.os.Message;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSON;
import com.example.stlink.model.request.CourseCreateRequest;
import com.example.stlink.model.response.BaseResponse;
import com.example.stlink.utils.httpUtils.PostBodyParamHttpUtils;

public class CreateCourseUtil {

    public static void createCourse(AppCompatActivity appCompatActivity, CourseCreateRequest courseCreateRequest, Handler handler, @Nullable String url) {

        new Thread(() -> {
            //fastJson将对象转换为JSON字符串
            String json = JSON.toJSONString(courseCreateRequest);

            new PostBodyParamHttpUtils() {
                @Override
                public void nextMethod(BaseResponse<Object> baseResponse) {
                    Message message = new Message();
                    message.obj = "success";
                    handler.sendMessage(message);
                }
                @Override
                public void failedMethod(BaseResponse<Object> baseResponse) {
                    Message message = new Message();
                    message.obj = baseResponse.getMsg();
                    handler .sendMessage(message);
                }
            }.postConnect(url, json);
        }).start();
    }

}
